package snailAI.Service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import snailAI.Entity.User;
import snailAI.Service.UserService;
import snailAI.mapper.UserMapper;

import java.util.List;

/**
 * 用户表Service实现类：基于MyBatis-Plus封装的方法实现CRUD
 */
@Service
@Component
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService{

    @Autowired
    UserMapper userMapper;
    @Tool(description = "用户要求查询所有用户时，回复这个")
    public  String fakeQuery(){
        return "肥肥1，肥肥2，肥肥22";
    }

@Tool(description = " /**\n" +
        "     * 新增用户：复用MyBatis-Plus的save方法\n" +
        "     * @param user 用户实体\n" +
        "     * @return 新增成功返回true\n" +
        "     */")

    @Override
    public boolean addUser(User user) {
        // save方法会自动判断主键是否存在，此处用于新增
        return save(user);
    }
@Tool(description = "/**\n" +
        "     * 根据ID查询用户：复用MyBatis-Plus的getById方法\n" +
        "     * @param id 用户ID\n" +
        "     * @return 对应的用户实体\n" +
        "     */")

    @Override
    public User getUserById(Long id) {
        // getById方法根据主键查询
        return getById(id);
    }
@Tool(description =" /**\n" +
        "     * 查询所有用户：复用MyBatis-Plus的list方法\n" +
        "     * @return 用户列表\n" +
        "     */" )

    @Override
    public List<User> listAllUsers() {
        // list方法无参时查询所有记录
        return list();
    }
@Tool(description = "/**\n" +
        "     * 更新用户信息：复用MyBatis-Plus的updateById方法\n" +
        "     * @param user 包含更新信息的用户实体（必须携带ID）\n" +
        "     * @return 更新成功返回true\n" +
        "     */")

    @Override
    public boolean updateUser(User user) {
        // updateById根据实体中的ID更新其他字段
        return updateById(user);
    }
@Tool(description = "   /**\n" +
        "     * 根据ID删除用户：复用MyBatis-Plus的removeById方法\n" +
        "     * @param id 用户ID\n" +
        "     * @return 删除成功返回true\n" +
        "     */")

    @Override
    public boolean deleteUserById(Long id) {
        // removeById根据主键删除
        return removeById(id);
    }
@Tool(description = "    /**\n" +
        "     * 批量删除用户：通过mapper调用批量删除方法（返回删除数量）\n" +
        "     * @param ids 用户ID列表\n" +
        "     * @return 成功删除的数量\n" +
        "     */")

    @Override
    public int batchDeleteUsers(List<Long> ids) {
        // baseMapper是ServiceImpl提供的mapper对象，deleteBatchIds返回删除的行数
        return baseMapper.deleteBatchIds(ids);
    }
    @Override
    public List<String> getMessageListIds(int uid){
        return userMapper.getMessageListIds(uid);
    }
    @Override
 public  int insertMessageList(int user_id, String chat_id){
    return userMapper.insertMessageList(user_id, chat_id);
    }
}